package xuegao.study.mall.rbac.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xuegao.study.mall.common.api.CommonResult;
import xuegao.study.mall.common.domain.UserDto;
import xuegao.study.mall.common.dto.rbac.UmsMemberRegisterDto;
import xuegao.study.mall.rbac.service.UmsMemberService;


@Api(tags = "UmdMemberController")
@Tag(name = "UmdMemberController", description = "会员管理相关接口")
@RestController
@RequestMapping(value = "/member")
public class UmsMemberController {

    private Logger logger = LoggerFactory.getLogger(UmsMemberController.class);

    @Autowired
    private UmsMemberService umsMemberService;

    @ApiOperation("会员注册")
    @PostMapping("/register")
    public CommonResult<Integer> register(@RequestBody UmsMemberRegisterDto memberDto) {
        int count = umsMemberService.register(memberDto);
        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }

    @ApiOperation("根据用户名获取通用用户信息")
    @GetMapping(value = "/loadByUsername")
    public UserDto loadUserByUsername(@RequestParam String username) {
        return umsMemberService.getUserByUsername(username);
    }
}
